package com.hunray.rent.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;
@Entity
@Table(name="t_group")
public class Group implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private Integer id;
	
	private String no;
	
	private String name;
	
	private String identityName;
	
	private String descr;
	
	private List<User> users;

	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator="tg_group")
	@TableGenerator(name="tg_group",table="t_id",pkColumnName="f_table",pkColumnValue="t_group",valueColumnName="f_id",initialValue=1,allocationSize=1)
	@Column(name="f_id")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	@Column(name="f_no",nullable=false,unique=true)
	@NotNull
	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	@Column(name="f_name",nullable=false,unique=true)
	@NotNull
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name="f_identity_name",nullable=false,unique=true)
	@NotNull
	public String getIdentityName() {
		return identityName;
	}

	public void setIdentityName(String identityName) {
		this.identityName = identityName;
	}

	@Column(name="f_descr")
	@Length(max=1024)
	public String getDescr() {
		return descr;
	}

	public void setDescr(String descr) {
		this.descr = descr;
	}
	@OneToMany(fetch=FetchType.LAZY,mappedBy="group")
	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	@Override
	public String toString() {
		return "Group [name=" + name + ", identityName=" + identityName + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Group other = (Group) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}
